﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;

namespace SoftwareMonkeys.LogClimber.Entities
{
    public class Log
    {
        private string dateStamp = string.Empty;
        public string DateStamp
        {
            get { return dateStamp; }
            set { dateStamp = value; }
        }

        private Entry[] childEntries = new Entry[] {};
        [XmlElement("Entry")]
        public Entry[] ChildEntries
        {
            get { return childEntries; }
            set
            {
                childEntries = value;
                if (childEntries != null)
                {
                    SetLog(childEntries);
                }
            }
        }


        public void AppendChild(Entry entry)
        {
            if (entry == null)
                throw new ArgumentNullException("entry");

            entry.Parent = null;
            SetLog(entry);

            List<Entry> list = new List<Entry>(childEntries);
            list.Add(entry);

            childEntries = list.ToArray();
        }

        public void SetLog(params Entry[] entries)
        {
            foreach (Entry entry in entries)
            {
                entry.Log = this;

                if (entry.ChildEntries != null)
                    SetLog(entry.ChildEntries);
            }
        }
    }
}
